package com.ww.cheappliers.sender.impl;

import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;

import com.ww.cheappliers.Message;
import com.ww.cheappliers.common.PropertyUtil;
import com.ww.cheappliers.common.StaticVar;
import com.ww.cheappliers.sender.Sender;

/**
 * 通过邮箱发消息
 * @author tengHy
 *
 */
public class EmailSender implements Sender, StaticVar {
	private String emailUser, emailPwd;
	public void send(Message message) {
		// TODO Auto-generated method stub
		
	}
	
	private void emailSend(){
		/*
		 Properties props = new Properties(); // 获取系统环境
         Authenticator auth = new EmailAuth(emailUser, emailPwd); // 进行邮件服务器用户认证
         props.put("mail.smtp.host", PropertyUtil.getProp(confKeyHost));
         props.put("mail.smtp.auth", "true");
         Session session = Session.getDefaultInstance(props, auth);
         // 设置session,和邮件服务器进行通讯。
         MimeMessage message = new MimeMessage(session);
         // message.setContent("foobar, "application/x-foobar"); // 设置邮件格式
         message.setSubject(MimeUtility.encodeText(MSG_SUBJECT_HEAD)); // 设置邮件主题
         message.setcon
         message.setText(mail_body); // 设置邮件正文
         message.setHeader(mail_head_name, mail_head_value); // 设置邮件标题
         message.setSentDate(new Date()); // 设置邮件发送日期
         Address address = new InternetAddress(mail_from, personalName);
         message.setFrom(address); // 设置邮件发送者的地址
         Address toAddress = new InternetAddress(mail_to); // 设置邮件接收方的地址
         message.addRecipient(Message.RecipientType.TO, toAddress);
         Transport.send(message); // 发送邮件
         System.out.println("send ok!");
		*/
	}
	
	protected static class EmailAuth extends Authenticator{
		private final String user, pwd;
		protected EmailAuth(String user, String pwd){
			this.user = user;
			this.pwd = pwd;
		}
		
		protected PasswordAuthentication getPasswordAuthentication() {
			return new PasswordAuthentication(user, pwd);
		}
	}

}
